package com.prs.crm.domain;

import javax.persistence.MappedSuperclass;
import javax.persistence.OneToOne;

import org.hibernate.annotations.Cascade;

import com.prs.crm.context.Constrains;
import com.prs.crm.domain.flow.WorkFlowProcess;

@SuppressWarnings("serial")
@MappedSuperclass
public class FlowEntity extends BaseEntity{
	
	private Integer flowstatus;
	
	@OneToOne
	@Cascade( { org.hibernate.annotations.CascadeType.ALL,
		org.hibernate.annotations.CascadeType.DELETE_ORPHAN })
	private WorkFlowProcess process;

	public void setProcess(WorkFlowProcess process) {
		this.process = process;
	}

	public WorkFlowProcess getProcess() {
		return process;
	}

	public void setFlowstatus(Integer flowstatus) {
		this.flowstatus = flowstatus;
	}

	public Integer getFlowstatus() {
		return flowstatus;
	}
	
	/**
	 * 返回是否处于流程中
	 * @return
	 */
	public boolean getProcessed()
	{
		if (this.flowstatus!=null 
				&& this.flowstatus==Constrains.WORKFLOWENTITY_STATE_PROCESS)
				return true;
		else
			return false;
	}
	
	/**
	 * 判断是否被锁定
	 * @return
	 */
	public boolean getLocked()
	{
		if (this.flowstatus!=null 
				&& (this.flowstatus==Constrains.WORKFLOWENTITY_STATE_PROCESS||this.flowstatus==Constrains.WORKFLOWENTITY_STATE_VALID))
			return true;
		else
			return false;
	}
	
}
